﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ZH.Infrastructure.Dto.Request.Pro;
using ZH.Infrastructure.Dto.Response.Pro;
using ZH.Service.Interface;

namespace ZH.Api.Admin.Controllers.Admin
{
    /// <summary>
    ///管理端· 产品/商品
    /// </summary>
    //[Authorize(Roles = "admin")]
    public class ProductController : BaseController
    {
        public readonly I_Pro_Service _Pro_Service;

        public ProductController(I_Login_Service login_Service, I_Pro_Service Pro_Service) : base(login_Service)
        {
            _Pro_Service = Pro_Service;

        }
        /// <summary>
        /// 获取产品列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Pro(int? page = 1, int? limit = 10, string? key = "")
        {
            var result = await _Pro_Service.Get_pro(new Pro_Response_Dto
            {
                page = page,
                limit = limit,
                key = key
            });

            return Ok(result);  
        }

        /// <summary>
        /// 禁用/启用产品
        /// </summary>
        /// <returns></returns>
        [HttpPost("DS_Pro/{id}")]
        public async Task<IActionResult> DS_Pro(string? id)
        {

            var result = await _Pro_Service.DS_Pro(id);

            return Ok(result);
        }

        /// <summary>
        /// 添加产品
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Pro(Pro_Request_Dto dto)
        {

            var result = await _Pro_Service.Add_Pro(dto);
            return Ok(result);
        }
        /// <summary>
        /// 删除产品
        /// </summary>
        /// <returns></returns>
        [HttpPost("Delete_Pro/{id}")]
        public async Task<IActionResult> Delete_Pro(string? id)
        {
            var result = await _Pro_Service.Delete_Pro(id);

            return Ok(result);
        }
        /// <summary>
        /// 修改产品
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_Pro(Pro_Request_Dto Dto)
        {
            {

                var result = await _Pro_Service.Update_Pro(Dto);

                return Ok(result);
            }

        }
    }
}
 